package informed.interact;

import cern.colt.matrix.DoubleMatrix1D;
import cern.colt.matrix.impl.DenseDoubleMatrix1D;
import cern.colt.matrix.impl.SparseDoubleMatrix1D;
import informed.matrix.SparseVector;
import informed.matrix.Utils;

public class Tests {
	
	public static void main(String[] args){
		// Two sparse vectors of equal length
		SparseVector a = new SparseVector();
		a.set(1, 2); a.set(3, 4); a.set(5, 6);
		System.out.println("a = " + a);
		SparseVector b = new SparseVector();
		b.setQuick(2, 2); b.setQuick(3, 4); b.setQuick(4, 6);
		System.out.println("b = " + b);
		System.out.println("Dot product: " + a.dotProduct(b));
		System.out.println("Sum: " + a.addVectors(b));
		System.out.println("NormL1: " + b.normL1() + " NormL2: " + b.normL2());
		System.out.println("Add Scalar: " + b.addScalar(1));
		System.out.println("Multiply: " + b.scalarProduct(2));
		// Remove one element from the second vector
		b.setQuick(3, 0);
		System.out.println("a = " + a);
		System.out.println("b = " + b);
		System.out.println("Dot product: " + a.dotProduct(b));
		System.out.println("Sum: " + a.addVectors(b));
		System.out.println("NormL1: " + b.normL1() + " NormL2: " + b.normL2());
		System.out.println("Add Scalar: " + b.addScalar(1));
		System.out.println("Multiply: " + b.scalarProduct(2));
		// Add two more elements to the second vector
		b.setQuick(2, 3); b.setQuick(3, 8); b.setQuick(5, 12);
		System.out.println("a = " + a);
		System.out.println("b = " + b);
		System.out.println("Dot product: " + a.dotProduct(b));
		System.out.println("Sum: " + a.addVectors(b));
		System.out.println("NormL1: " + b.normL1() + " NormL2: " + b.normL2());
		System.out.println("Add Scalar: " + b.addScalar(1));
		System.out.println("Multiply: " + b.scalarProduct(2));
	}
	
	public static void testUtils(){
		double[] dx = {8,0,5,4,6,2,5,4};
		double[] dy = {4,5,2,6,5,5,0,8};
		double k = 0.5;
		SparseDoubleMatrix1D x = new SparseDoubleMatrix1D(dx);
		DenseDoubleMatrix1D y = new DenseDoubleMatrix1D(dy);
		DoubleMatrix1D a = Utils.addVectors(x,y);
		DoubleMatrix1D b = Utils.multByScalar(a, k);
		a = Utils.addVectors(a,b);
		System.out.print("a: ");
		System.out.println(a);
		System.out.print("b: ");
		System.out.println(b);
		System.out.print("x: ");
		System.out.println(x);
		System.out.print("y: ");
		System.out.println(y);
		
	}

}
